a = int(input())
k = 0
r = a // 1000

r1 = a // 100
r2 = a // 10
r3 = a
g = []
if r % r == 0 and r % 1 == 0 and r % 2 != 0 and r % 3 != 0 and r % 5 != 0 and r % 6 != 0 and r % 7 != 0 and r % 8 != 0 and r % 9 != 0:
    g.append(r)
else:
    print(0)
if r1 % r1 == 0 and r1 % 1 == 0 and r1 % 2 != 0 and r1 % 3 != 0 and r1 % 5 != 0 and r1 % 6 != 0 and r1 % 7 != 0 and r1 % 8 != 0 and r1 % 9 != 0:
    g.append(r1)
else:
    print(0)
if r2 % r2 == 0 and r2 % 1 == 0 and r2 % 2 != 0 and r2 % 3 != 0 and r2 % 5 != 0 and r2 % 6 != 0 and r2 % 7 != 0 and r2 % 8 != 0 and r2 % 9 != 0:
    g.append(r2)
else:
    print(0)
if r3 % r3 == 0 and r3 % 1 == 0 and r3 % 2 != 0 and r3 % 3 != 0 and r3 % 5 != 0 and r3 % 6 != 0 and r3 % 7 != 0 and r3 % 8 != 0 and r3 % 9 != 0:
    g.append(r3)
else:
    print(0)
s = max(g)
print(s)
